package com.xizi.lotterySystem.dao.mapper;

import com.xizi.lotterySystem.controller.param.PageListParam;
import com.xizi.lotterySystem.dao.dataobject.PrizeDO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface PrizeMapper {

    @Insert("insert into prize (name,description,price,image_url) " +
            " values (#{name},#{description},#{price},#{imageUrl})")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    int insertPrize(PrizeDO param);

    @Select("select count(*) from prize where status = 0")
    long selectPrizeCount();

    @Select("SELECT * FROM prize where status = 0 ORDER  BY id DESC LIMIT  #{pageSize} OFFSET #{offset}")
    List<PrizeDO> selectPrizeList(PageListParam param);

    @Select("<script>" +
            " select * from prize" +
            " where id in " +
            " <foreach collection='ids' item='id' open='(' separator=',' close=')'> " +
            " #{id}" +
            " </foreach>" +
            " </script> ")
    List<PrizeDO> selectPrizeByIds(List<Long> ids);

    @Select("select * from prize where id = #{prizeId}")
    PrizeDO selectById(Long prizeId);
}
